package common;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 排列算法
 *
 * 元素有重复的情况，不去重
 */
public class Permutation {
    public static void main(String[] args) {
        System.out.println(permutation(Arrays.asList("1", "2", "3", "1"), 2));
    }

    public static List<String> permutation(List<String> list, int len) {
        Stream<String> stream = list.stream();
        for (int i = 0; i < len - 1; i++) {
            stream = stream.flatMap(ele -> list.stream().map(ele::concat));
        }
        return stream.collect(Collectors.toList());
    }
}
